home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programmierung
/
Power-Programmierung (Tewi)(1994).iso
/
tipi
/
sqrt.tpi
< prev
next >
Wrap
Text File
|
1993-11-07
|
668b
|
36 lines
# SQRT.TPI
# A fixed point square root routine
# by Kent Peterson
defvar root
defvar x
define guess
x fetch 2 / root store
enddef
define sqrt
x fetch root fetch /
root fetch + 2 /
root fetch over
> if root store sqrt endif
enddef
"Pick a number: " print$
getnum dup
"The square root of " print$
print
" is " print$
1000000 * # Multiply the number up to get 3
# decimal place accuracy
x store
guess
sqrt
dup 1000 / # Divide to get the integer part
dup print # print the integer part
"." print$ # print the decimal point
1000 * - # Get the fractional part
print cr # and print it.
begin key until